﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VoxelBlock.VoxelBlock3D;
using VoxelBlock;using Vector3Int = VoxelBlock.Vector3Int;

/// <summary>
/// 笔刷添加
/// </summary>
public class OperationImplementBrushAdd : OperationImplement
{

    //public OperationImplementBrushAdd(ProxyOperation proxy) : base(proxy)
    //{
       
    //}

    public override void Start(StartArg arg)
    {
        base.Start(arg);

    }

    public override void Run(RunArg arg)
    {
        var array = BasicAlgorithm.GetLineBlock3D(arg.updateStartPosition, arg.nowSelectPosition, arg.nowSelectUVKey);
        historyRecordBreakList.AddRange(nowDrawVoxel3DCore.DrawAddBlock(array));
    }

    public override void Over(OverArg arg)
    {
        if (isStop)
        {
            if (historyRecordBreakList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Add, historyRecordFrontList, historyRecordBreakList);
                historyRecordBreakList = new List<SimpleVoxel>();
            }
        }
        else
        {
            if (historyRecordBreakList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Add, historyRecordFrontList, historyRecordBreakList);
                historyRecordBreakList = new List<SimpleVoxel>();
                //historyRecordFrontList = new List<SimpleVoxel>();
            }
            else
            {
                var serializeVoxel = nowDrawVoxel3DCore.DrawAddBlock(new Voxel3D[] { new Voxel3D(arg.nowSelectPosition, arg.nowSelectUVKey) });
                if (serializeVoxel.Length > 0)
                {
                    proxy.Write(VoxelCategories.Operation.Add, historyRecordFrontList, serializeVoxel);
                }
            }
        }


    }


}
